<?php
namespace app\index\controller;

use think\exception\Handle;
class ExceptionHandler extends Handle
{
    /**
     * 错误自定义返回内容
     * @param:
     * @return: json
     */
    public function render(\Exception $e){
        if(config('app_debug')){
            //如果开启debug则正常报错
            return parent::render($e);
        }else{
            if(request()->isPost() || request()->isAjax())
            {
                $error_msg['code'] = 500;
                $error_msg['msg']  = '内部请求错误';
                $error_msg['data'] = [];
                return json($error_msg);
            }else{
                header("location:/");
            }
        }
    }
}